package com.smarttiger.zero.logic;

import cn.hutool.core.util.ClassUtil;
import com.smarttiger.zero.admin.service.InterfaceService;
import com.smarttiger.zero.admin.service.MenuService;
import com.smarttiger.zero.admin.service.UsersGroupService;
import com.smarttiger.zero.admin.service.UsersService;
import io.micrometer.core.instrument.util.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationListener;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.*;

@Configuration
public class InitLogicConfig implements ApplicationListener<ContextRefreshedEvent> {

    List<Map<String, String>> mapList = new ArrayList<>();

    @Autowired
    MenuService menuService;

    @Autowired
    UsersService usersService;

    @Autowired
    UsersGroupService usersGroupService;

    @Autowired
    InterfaceService interfaceService;

    @Bean(name = "logicMaps")
    public List<Map<String, String>> interfaceLogicMap(){
        return mapList;
    }

    @Override
    public void onApplicationEvent(ContextRefreshedEvent event) {
        Set<Class<?>> classes = ClassUtil.scanPackage("com.smarttiger.zero.logic.impl");
        for (Class<?> aClass : classes) {
            Map<String,String> _m = new HashMap<>();
            _m.put("label",aClass.getSimpleName());
            _m.put("key",aClass.getName());
            if(StringUtils.isNotEmpty(aClass.getSimpleName()) && aClass.getSimpleName().endsWith("Logic")){
                mapList.add(_m);
            }
        }
    }
}
